package com.service.gmall.web.controller;

import com.service.gmall.common.result.Result;
import com.service.gmall.feign.product.CategoryFeignClient;
import com.service.gmall.model.to.CategoryTreeTo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author alpha
 * @className: IndexPageController
 * @date 2022/8/26 10:13
 * @Description
 */
@Api(tags = "欢迎页")
@Controller
public class IndexPageController {
    @Autowired
    CategoryFeignClient categoryFeignClient;
    /**
     * @param
     * @description: 跳转首页
     * @return: java.lang.String
     * @author: alpha
     * @date: 2022/8/26 10:16
     */
    @ApiOperation("欢迎页")
    @GetMapping({"/","/index"})
    public String index(Model model){
        // 远程调用查询菜单
        Result<List<CategoryTreeTo>> result = categoryFeignClient.getAllCategoryTree();

        if (result.isOk()){
            //远程调用成功
            List<CategoryTreeTo> resultData = result.getData();
            model.addAttribute("list",resultData);
        }
        return "index/index";
    }
}
